package com.zelin.yang.kotlin_demo.page

import com.shehuan.wanandroid.base.net.RequestManager
import com.shehuan.wanandroid.base.net.RetrofitManager
import com.shehuan.wanandroid.base.net.exception.ResponseException
import com.shehuan.wanandroid.base.net.observer.BaseObserver
import com.zelin.yang.kotlin_demo.Base.BaseFragment
import com.zelin.yang.kotlin_demo.R
import com.zelin.yang.kotlin_demo.entry.BannerBean
import com.zelin.yang.kotlin_demo.entry.LoginBean
import com.zelin.yang.kotlin_demo.net.WanAndroidApis
import com.zelin.yang.kotlin_demo.util.ToastUtil
import com.zelin.yang.kotlin_demo.weight.BannerImageLoader
import kotlinx.android.synthetic.main.home_fragment.*

class HomeFragment: BaseFragment() {
    override fun getLayoutId(): Int {
        return R.layout.home_fragment
    }

    override fun Initview() {
        banner.setImageLoader(BannerImageLoader())
    }

    override fun initDate() {
        getBanner()
        //login()
    }



    private fun getBanner() {
        RequestManager.execute(RetrofitManager.create(WanAndroidApis::class.java).banner(),
                object : BaseObserver<List<BannerBean>>() {
                    override fun onSuccess(data: List<BannerBean>) {
                        val bannerBeans: List<BannerBean> = data
                        val titles = arrayListOf<String>()
                        val imgaes = arrayListOf<String>()
                        for (bannerbean in bannerBeans) {
                            titles.add(bannerbean.title)
                            imgaes.add(bannerbean.imagePath)
                        }
                        banner.setImages(imgaes).setBannerTitles(titles).start()
                    }

                    override fun onError(e: ResponseException) {

                    }
                })
    }

}


